import vtkActor from "@kitware/vtk.js/Rendering/Core/Actor";
import {ACTOR_TYPE} from "../interface";
import {BActor} from "./BActor";
import vtkArrowSource from "@kitware/vtk.js/Filters/Sources/ArrowSource";
import {Vector3} from "stl-typescript";
import vtkMapper from "@kitware/vtk.js/Rendering/Core/Mapper";
import vtkSphereSource from "@kitware/vtk.js/Filters/Sources/SphereSource";

export class AxisActor extends BActor {
    instance = "";
    children: vtkActor [] = [];
    type: ACTOR_TYPE = ACTOR_TYPE.WIDGET;
    createdBy: string = "default";
    xAxisActor: vtkActor = vtkActor.newInstance();
    yAxisActor: vtkActor = vtkActor.newInstance();
    zAxisActor: vtkActor = vtkActor.newInstance();
    centerActor: vtkActor = vtkActor.newInstance();
    readonly isAxisActor: boolean = true;

    position: Vector3 = new Vector3(0, 0, 0)

    constructor() {
        super();
        this.init();
        this.children.push(this.xAxisActor, this.yAxisActor, this.zAxisActor, this.centerActor)
    }

    init() {
        const arrowSource = vtkArrowSource.newInstance({
            tipResolution: 6,
            tipRadius: 0.1,
            tipLength: 0.35,
            shaftResolution: 6,
            shaftRadius: 0.03,
            invert: false,
            direction: [1.0, 0.0, 0.0]
        });
        const xAxisMapper = vtkMapper.newInstance()
        xAxisMapper.setInputConnection(arrowSource.getOutputPort());
        this.xAxisActor.setMapper(xAxisMapper)
        this.xAxisActor.getProperty().setColor(1, 0, 0);
        this.xAxisActor.setPosition(0.35, 0, 0)
        const yArrowSource = vtkArrowSource.newInstance({
            tipResolution: 6,
            tipRadius: 0.1,
            tipLength: 0.35,
            shaftResolution: 6,
            shaftRadius: 0.03,
            invert: false,
            direction: [0.0, 1.0, 0.0]
        });
        const yAxisMapper = vtkMapper.newInstance()
        yAxisMapper.setInputConnection(yArrowSource.getOutputPort());
        this.yAxisActor.setMapper(yAxisMapper)
        this.yAxisActor.getProperty().setColor(0, 1, 0);
        this.yAxisActor.setPosition(0, 0.35, 0)
        const zArrowSource = vtkArrowSource.newInstance({
            tipResolution: 6,
            tipRadius: 0.1,
            tipLength: 0.35,
            shaftResolution: 6,
            shaftRadius: 0.03,
            invert: false,
            direction: [0.0, 0.0, 1.0]
        });
        const zAxisMapper = vtkMapper.newInstance()
        zAxisMapper.setInputConnection(zArrowSource.getOutputPort());
        this.zAxisActor.setMapper(zAxisMapper)
        this.zAxisActor.getProperty().setColor(0, 0, 1);
        this.zAxisActor.setPosition(0, 0, 0.35)
        // * 中心球
        const sphereSource = vtkSphereSource.newInstance();
        sphereSource.setRadius(0.1);
        sphereSource.setThetaResolution(20);
        sphereSource.setPhiResolution(20);
        const sphereMapper = vtkMapper.newInstance();
        sphereMapper.setInputConnection(sphereSource.getOutputPort());
        this.centerActor.setMapper(sphereMapper);
        this.centerActor.getProperty().setColor(0, 0, 0);
    }
}